import { createApp } from 'vue'
import'./api/mock'
import router from './router'
import App from './App.vue'
import'./assets/less/index.less'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import{createPinia}from 'pinia'
import api from './api/api'
import{useAllDtaStore} from "./store"
function isRoute(to){
 let res=router.getRoutes()
 let resFl=res.filter(item=>item.path===to.path)
 return resFl.length>0

}
router.beforeEach((to,from)=>{
  if(to.path!=='/login'&& !store.state.token){
    return {name:"login"}
  }
  if(!isRoute(to)){
    return {name:"404"}
  }
})
const app=createApp(App)
const pinia=createPinia()

app.use(pinia)
const store=useAllDtaStore()
// 全局挂载api
app.config.globalProperties.$api=api;

store.addMenu(router,"refresh")

app.use(router).use(ElementPlus).mount('#app')
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}